import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
from sklearn.metrics import accuracy_score
import os
from sklearn.externals import joblib
import numpy as np  
import matplotlib.pyplot as plt


models_name=["RandomForestClassifier","LogisticRegression","kNN","DecisionTree","MLPClassifier","NaiveBayes","SVM","Bagging"]

def test_algorithms(test_x,test_y,model_name):
    dirs = "../testModel"
    model_temp = joblib.load(dirs+"/"+model_name+".model")
    predictions=model_temp.predict(test_x) 
    accuracy= accuracy_score(test_y, predictions)
    print(model_name,"准确度:",accuracy)
    return accuracy

def show_draw(all_accuracy,times,algorithms_number):
    
    plt.figure()
    for i in range(0,times):
        x=[]
        for j in range(i,len(all_accuracy),algorithms_number):
            x.append(all_accuracy[j])
        plt.plot(range(0,times),x)  
    plt.xlabel("times")  
    plt.ylabel("accury")  
    plt.title("A simple plot")
    
    
if __name__ == '__main__':
    
    all_accuracy=[] 
    
    for i in range(0,2):
        print(i)
        x_train, x_test, y_train, y_test=load_file_test()
        
        for item in models_name:     
            all_accuracy.append(test_algorithms(x_test,y_test,item))
    show_draw(all_accuracy,2,8)            